//package com.example.demo.controller;
//
//import java.io.IOException;
//import java.net.MalformedURLException;
//import java.net.URL;
//
//import javax.print.DocFlavor;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//
//import com.example.demo.utils.PropertiesUtils;
//import com.ideabank.sap.webservice.TokenCheckServiceService;
//import com.ideabank.sap.webservice.TokenCheckWS;
//import com.ideabank.sap.webservice.VerifyIdTRet;
//import org.apache.commons.lang.StringUtils;
//import org.apache.http.client.ClientProtocolException;
//import org.apache.http.client.fluent.Form;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//
//import com.thoughtworks.xstream.XStream;
//import com.thoughtworks.xstream.converters.basic.DateConverter;
//
//@Controller
//@RequestMapping("/test")
//public class TestController {
//
//
//    @RequestMapping("/toLogin.htm")
//    public String toLogin(){
//        return "system/index";
//    }
//
//    @RequestMapping("/toIndex.htm")
//    public String toIndex(){
//        return "system/dash";
//    }
//
//
//    @RequestMapping("/toIndex2.htm")
//    public String toIndex2(){
//        return "system/dash2";
//    }
//
//    @RequestMapping("/toIndex3.htm")
//    public String toIndex3(){
//        return "system/dash3";
//    }
//
//    @RequestMapping("/toAuth.htm")
//    public String toAuth(){
//        return "system/auth";
//    }
//
//
//    @RequestMapping("/test_four.json")
//    @ResponseBody
//    public String test_four(HttpServletRequest resquest,HttpServletResponse response) throws ClientProtocolException, IOException {
//        response.setHeader("Access-Control-Allow-Origin", "*");
//
//        AuthOnlineRequest request = new AuthOnlineRequest();
//
//        request.setVersion("1.0");
//        request.setPepId("ff80808168ecdf4c0168f0d000f303a7");
//        request.setSubjectId("ff80808168ecdf4c0168f0d9b7730741");
//        request.setObjectId("ff80808168ecdffe0168f0d6540404ef");
//
//        StringBuffer sb = new StringBuffer();
//        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>").append("\n");
//        XStream stream = new XStream();
//
//        stream.registerConverter(
//                new DateConverter("yyyy-MM-dd HH:mm:ss", new String[] { "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd" }));
//        stream.processAnnotations(request.getClass());
//        stream.setMode(XStream.NO_REFERENCES);
//        String objXmlStr = stream.toXML(request);
//        sb.append(objXmlStr);
//        System.out.println(sb.toString());
//        String resultStr = org.apache.http.client.fluent.Request.Post("http://192.168.7.102:9090/authOnline/checkAuth.json")
//                .bodyForm(Form.form().add("request", sb.toString()).build()).execute().returnContent().asString();
//        return resultStr;
//    }
//
//
//    @RequestMapping("/test_one.json")
//    @ResponseBody
//    public String getTestString1(HttpServletRequest resquest,HttpServletResponse response) throws MalformedURLException {
//        response.setHeader("Access-Control-Allow-Origin", "*");
//        URL url = new URL(PropertiesUtils.getPorp("webservice.url"));
//        TokenCheckServiceService wsImpl = new TokenCheckServiceService(url);
//        TokenCheckWS ws = wsImpl.getTokenCheckServicePort();
//        String res = ws.generatorChallenge();
//        return res;
//    }
//
//    @RequestMapping("/test_two.json")
//    @ResponseBody
//    public String getTest2(HttpServletRequest resquest,HttpServletResponse response,String challenge,String identityTicket) throws MalformedURLException {
//        response.setHeader("Access-Control-Allow-Origin", "*");
//        URL url = new URL(PropertiesUtils.getPorp("webservice.url"));
//        TokenCheckServiceService wsImpl = new TokenCheckServiceService(url);
//        TokenCheckWS ws = wsImpl.getTokenCheckServicePort();
//        VerifyIdTRet res = ws.verifyIdentityTicket(PropertiesUtils.getPorp("server.id"), challenge, identityTicket);
//        if(res==null){
//            return "无验证结果";
//        }else{
//            return res.getResult();
//        }
//    }
//
//
//    @RequestMapping("/test_three.json")
//    @ResponseBody
//    public ActionResult getTest3(HttpServletRequest resquest,HttpServletResponse response,String challenge,String identityTicket) throws MalformedURLException {
//        response.setHeader("Access-Control-Allow-Origin", "*");
//        URL url = new URL(PropertiesUtils.getPorp("webservice.url"));
//        ActionResult ar=new ActionResult();
//        TokenCheckServiceService wsImpl = new TokenCheckServiceService(url);
//        TokenCheckWS ws = wsImpl.getTokenCheckServicePort();
//        VerifyIdTRet res = ws.verifyIdentityTicket(PropertiesUtils.getPorp("server.id"),challenge,identityTicket);
//        if(res!=null && res.getResult()!=null){
//            String result = StringUtils.substringBefore(res.getResult(), "</error>");
//            result = StringUtils.substringAfter(result, "<error>");
//            if(StringUtils.isBlank(result)){
//                ar.setSuccess(true);
//            }else{
//                ar.setSuccess(false);
//                ar.setMsg(result);
//            }
//
//        }
//        return ar;
//    }
//
//    @RequestMapping("/test_five.json")
//    @ResponseBody
//    public ActionResult getTest5() throws MalformedURLException {
//        String challenge=PropertiesUtils.getPorp("webservice.challenge");
//        String identityTicket=PropertiesUtils.getPorp("webservice.identityTicket");
//        URL url = new URL(PropertiesUtils.getPorp("webservice.url"));
//        ActionResult ar=new ActionResult();
//        TokenCheckServiceService wsImpl = new TokenCheckServiceService(url);
//        TokenCheckWS ws = wsImpl.getTokenCheckServicePort();
//        VerifyIdTRet res = ws.verifyIdentityTicket(PropertiesUtils.getPorp("server.id"),challenge,identityTicket);
//        if(res!=null && res.getResult()!=null){
//            String result = StringUtils.substringBefore(res.getResult(), "</error>");
//            result = StringUtils.substringAfter(result, "<error>");
//            if(StringUtils.isBlank(result)){
//                ar.setSuccess(true);
//            }else{
//                ar.setSuccess(false);
//                ar.setMsg(result);
//            }
//
//        }
//        return ar;
//    }
//}
//
